package com.ruoyi.od.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.od.domain.StockAlertSetting;
import com.ruoyi.od.service.IStockAlertSettingService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 库存预警设置Controller
 * 
 * @author ruoyi
 * @date 2025-06-23
 */
@Controller
@RequestMapping("/od/setting")
public class StockAlertSettingController extends BaseController
{
    private String prefix = "od/setting";

    @Autowired
    private IStockAlertSettingService stockAlertSettingService;

    @RequiresPermissions("od:setting:view")
    @GetMapping()
    public String setting()
    {
        return prefix + "/setting";
    }

    /**
     * 查询库存预警设置列表
     */
    @RequiresPermissions("od:setting:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(StockAlertSetting stockAlertSetting)
    {
        startPage();
        List<StockAlertSetting> list = stockAlertSettingService.selectStockAlertSettingList(stockAlertSetting);
        return getDataTable(list);
    }

    /**
     * 导出库存预警设置列表
     */
    @RequiresPermissions("od:setting:export")
    @Log(title = "库存预警设置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(StockAlertSetting stockAlertSetting)
    {
        List<StockAlertSetting> list = stockAlertSettingService.selectStockAlertSettingList(stockAlertSetting);
        ExcelUtil<StockAlertSetting> util = new ExcelUtil<StockAlertSetting>(StockAlertSetting.class);
        return util.exportExcel(list, "库存预警设置数据");
    }

    /**
     * 新增库存预警设置
     */
    @RequiresPermissions("od:setting:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存库存预警设置
     */
    @RequiresPermissions("od:setting:add")
    @Log(title = "库存预警设置", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(StockAlertSetting stockAlertSetting)
    {
        return toAjax(stockAlertSettingService.insertStockAlertSetting(stockAlertSetting));
    }

    /**
     * 修改库存预警设置
     */
    @RequiresPermissions("od:setting:edit")
    @GetMapping("/edit/{settingId}")
    public String edit(@PathVariable("settingId") String settingId, ModelMap mmap)
    {
        StockAlertSetting stockAlertSetting = stockAlertSettingService.selectStockAlertSettingBySettingId(settingId);
        mmap.put("stockAlertSetting", stockAlertSetting);
        return prefix + "/edit";
    }

    /**
     * 修改保存库存预警设置
     */
    @RequiresPermissions("od:setting:edit")
    @Log(title = "库存预警设置", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(StockAlertSetting stockAlertSetting)
    {
        return toAjax(stockAlertSettingService.updateStockAlertSetting(stockAlertSetting));
    }

    /**
     * 删除库存预警设置
     */
    @RequiresPermissions("od:setting:remove")
    @Log(title = "库存预警设置", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(stockAlertSettingService.deleteStockAlertSettingBySettingIds(ids));
    }
}
